home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13877 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  61 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.inap.net!news1!ind-001-236-76
  3. From: dlmiller@iquest.net (Doug Miller)
  4. Subject: Re: reversing a string
  5. X-Nntp-Posting-Host: ind-001-236-76.iquest.net
  6. Message-ID: <DpnF5t.9xD@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Network Services
  9. X-Newsreader: News Xpress Version 1.0 Beta #2.1
  10. References: <829058514snz@genesis.demon.co.uk> <4ke0b9$rk5@grimsel.zurich.ibm.com> <DpM3Kz.6t4@iquest.net> <4kfoda$eue@grimsel.zurich.ibm.com>
  11. Date: Wed, 10 Apr 1996 13:39:29 GMT
  12.  
  13. wgk@zurich.ibm.com (Keith Whittingham) wrote:
  14. >In <DpM3Kz.6t4@iquest.net>, dlmiller@iquest.net (Doug Miller) writes:
  15. >>wgk@zurich.ibm.com (Keith Whittingham) wrote:
  16. >>>Ole!  (pronounced Spanishly but written 'olleh')
  17. >>>
  18. >>>Well here's a starter - no second variable but two recursive functions.
  19. >>>Hopefully that can be reduced to one if my project can spare the time.
  20. >>>(Note to manager: don't worry, just joking).
  21. >>>
  22. >>>#include <stdio.h>
  23. >>>
  24. >>>void RecRev2(char *s)
  25. >>>  {
  26. >>>  if(s[1])
  27. >>>    {
  28. >>>    if(s[2])
  29. >>>      {
  30. >>>      RecRev2(&s[1]);
  31. >>>      }
  32. >>>    s[0] ^= s[1]; s[1] ^= s[0]; s[0] ^= s[1];
  33. >>>    }
  34. >>>  }
  35. >>>
  36. >>>void RecRev1(char *s)
  37. >>>  {
  38. >>>  if(s && *s)
  39. >>>    {
  40. >>>    RecRev2(s);
  41. >>>    RecRev1(&s[1]);
  42. >>>    }
  43. >>>  }
  44. >>>
  45. >>>int main(int argc, char *argv)
  46. >>>  {
  47. >>>  char *s = "Hello";
  48. >>>  RecRev1(s);
  49. >>>  puts(s);
  50. >>>  return 0;
  51. >>>  }
  52. >>>
  53. >>This breaks if the string begins and ends with the same character.
  54. >
  55. >What are you talking about?!
  56. >
  57. >Keith
  58. >
  59. >
  60. My mistake.  I was sleeping when I wrote that.  Sorry.
  61.